	package com.pk.android.view.adapter;

	import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.pk.android.R;
import com.pk.android.model.Team;

	public class MyTeamsAdapter extends ArrayAdapter<Team>{
		private Context context;
		private List<Team> values;
		
	  public MyTeamsAdapter(Context context, List<Team> values) {
	    super(context, R.layout.listview_my_team_item, values);
	    
	    this.context = context;
	    this.values = values;
	  }	  
	  

	  @Override
	  public View getView(int position, View convertView, ViewGroup parent) {
	    
		  View rowView; 
		  if(convertView == null) 
		  {
			  LayoutInflater vi = LayoutInflater.from(this.context);
			  rowView = vi.inflate(R.layout.listview_my_team_item, null);
		  } else {
			  rowView= convertView;
		  }
		  
		  Team team = values.get(position);
		  if(team != null)
		  {
			  ((TextView)rowView.findViewById(R.id.txt_position)).setText(String.format("%d", position+1));
			  ((TextView)rowView.findViewById(R.id.txt_name)).setText(team.getName());
			  ((TextView)rowView.findViewById(R.id.txt_points)).setText(String.format("%d", team.getPoints()));
			  
			  ((TextView)rowView.findViewById(R.id.txt_wins)).setText(String.format("%d", 3*position));
			  ((TextView)rowView.findViewById(R.id.txt_loses)).setText(String.format("%d", 1*position));
			  ((TextView)rowView.findViewById(R.id.txt_draws)).setText(String.format("%d", 2*position));
		  }
		  
		  return rowView;
	  }

	  @Override
	  public boolean isEnabled(int position) {
	  	// TODO Auto-generated method stub
	  	return true;
	  }
	}
